<?php
session_start();
  include('../include/db_connect.php');

function inDB(){
$password = md5($_SERVER['PHP_AUTH_PW']);
$queryL="SELECT idUSERNAME, gebruikers_naam, wachtwoord FROM USERNAME
                  WHERE BINARY
                  gebruikers_naam='".$_SERVER['PHP_AUTH_USER']."'
                  AND
                  wachtwoord='".$password."'
                  AND
                  admin = 1
                  AND
                  status='act'";
                  

/*
gebruikers_naam='Muurverf'
                  //wachtwoord='".$_SERVER['PHP_AUTH_PW']."'";*/


$resL=   mysql_query($queryL) or die(mysql_error());
$usR =   mysql_fetch_array($resL);
if ($usR===false) return false;
return $usR['idUSERNAME'];
}

$usR = inDB();


?>
<style type="text/css">
div#noPermission{
margin-left:auto;
margin-right:auto;
text-align:center;
}
#noPermission a{
text-decoration:none;
color: #000000;
}
#noPermission a:hover{
text-decoration:none;
color: #ff0000;
}
#noPermissionImage a{
margin-top:-30px;
margin-left:auto;
margin-right:auto;
background-image:url('images_admin/icon_stop.png');
display:block;
width:512px;
height:512px;
text-decoration:none;
color: #000000;
}
#noPermissionImage a:hover{
margin-top:-30px;
margin-left:auto;
margin-right:auto;
background-image:url('images_admin/icon_stop2.png');
display:block;
width:512px;
height:512px;
text-decoration:none;
color: #ff0000;
}

</style>
<?php
if(!isset($_SERVER['PHP_AUTH_USER'])||$usR===false)
  {
    Header("WWW-Authenticate: Basic realm=\"Vul je gebruikersnaam en wachtwoord in\"");
    Header("HTTP/1.0 401 Unauthorized");
    echo '<div id="noPermission">';
	echo '<h1> U heeft geen authorisatie om hier te komen.</h1><br>';
	echo '<div id="noPermissionImage">';
	echo '<a href="../index.php"></a>';
	echo '</div>';
	echo '<h1> <a href="../index.php">Klik hierom terug te gaan naar de index site</a> </h1><br>';
	echo '</div>';

   }
else
  {
    //echo $usR;

?>
		<!-- Start of Page Header -->
		
	<?php include("include/admin_header.php"); ?>


		<!-- End of Page Header -->
	<?php include("include/admin_menu.php"); ?>
	
	<?php
$data = " ";
$dropdown = "";
if (isset($_POST['operation']))
{
		$P_key = array_keys($_POST);
		//dan sel query

	//
	if(isset($_POST['operation']))
	{
		if($_POST['operation']=='select')	
		{
		$selquery="SELECT omschrijving FROM PAGINAOMSCHRIJVING WHERE naam_pagina='".$_POST['select']."'";
			//echo "$selquery"; 
			$selresult = mysql_query($selquery) or die(mysql_error());
			$row = mysql_fetch_assoc($selresult);
			$data = $row['omschrijving'];
			
		}
		else
		{
			$updquery="UPDATE PAGINAOMSCHRIJVING SET omschrijving ='".$_POST['editor1']."' WHERE naam_pagina='".$_POST['select']."'";
			$updresult = mysql_query($updquery) or die(mysql_error());
			$selquery="SELECT omschrijving FROM PAGINAOMSCHRIJVING WHERE naam_pagina='".$_POST['select']."'";
			//echo "$updquery"; 
			$selresult = mysql_query($selquery) or die(mysql_error());
			$row = mysql_fetch_assoc($selresult);
			$data = $row['omschrijving'];
			

			
		}
	}
}

//$resL=   mysql_query($queryL) or die(mysql_error());
//$usR =   mysql_fetch_array($resL);

	echo "	<form method=POST action='paginabeheer.php'>";
	echo "	<table border='0'> ";
	echo '<tr><td>'; 
	echo '<select id="select" name="select">';
	$option = "SELECT naam_pagina FROM PAGINAOMSCHRIJVING"; 
	$sql = mysql_query($option);
	if(!isset($_POST['operation'])){
	echo '<option name="wattedoen" value= "" selected ="selected"></option>';
	while($record = mysql_fetch_assoc($sql))
		{	
			echo '<option name = "wattedoen" value="'.$record['naam_pagina'].'">'.$record['naam_pagina'].'</option>';
			
		}

	}
	else
	{
	echo '<option name="wattedoen" value= "" ></option>';
			while($record = mysql_fetch_assoc($sql))
		{
			$rowophalen = $record['naam_pagina'];
			if($rowophalen== $_POST['select']){
			echo '<option name = "wattedoen" value="'.$record['naam_pagina'].'" selected ="selected">'.$record['naam_pagina'].'</option>';
			} else{
				if($record['naam_pagina'] == $_POST['select'])//houd het dropdown menu geselecteerd
				{
					echo '<option name = "wattedoen" value="'.$record['naam_pagina'].'" selected="selected">'.$record['naam_pagina'].'</option>';		
				}
				else 
				{
				echo '<option name = "wattedoen" value="'.$record['naam_pagina'].'" >'.$record['naam_pagina'].'</option>';
				}
		}
		}
	}
	echo '</select>';
	echo '</td>';
	
	if(isset($_POST['operation']))
	{
		if($_POST['operation']=='select')
		{
			echo '<td><p style="font-size:14px;color:#000000;  text-align:center;"> De pagina <b>'.$_POST['select'].'</b> is geselecteerd</p></td>';
		}
		if($_POST['operation']=='update')
		{
			if($updresult==false)
			{
				echo '<td><p style="font-size:14px;color:#000000; text-align:center;">De update kon niet worden uitgevoerd. Probeer het nogmaals. Mocht het probleem blijven bestaan, neem contact op met de administrator</p></td>';
			}	
			else if($updresult==true)
			{
				echo '<td><p style="font-size:14px;color:#000000;  text-align:center;"> De pagina <b>'.$_POST['select'].'</b> is succesvol geupdate</p></td>';
				?>

				<?php
			}
		}
	}echo '</tr>';
	echo '</table>';
	echo '<table>';
	echo '<tr><td><textarea class="ckeditor" id="editor1" name="editor1"  style="background-color:white; resize: none;">'.$data.'</textarea></td></tr>';
	echo"<tr><td><input name='operation' type='radio' value='select'>selecteer</td></tr>";
	if(isset($_POST['operation']))
	{
		if($_POST['operation']=='select')
		{
			echo"<tr><td><input name='operation' type='radio' value='update'>update</td></tr>";
		}
	}
	echo "<tr><td><input type='submit' name='submit' value='submit'></td></tr>";
	//echo '<tr><td><button type="submit" value="select">Select</button></td>
	//echo '<td><button type="submit" value="update">Update</button></td></tr>';
	echo '</table>';
	echo '</form>';
	?>
	<?php include("include/admin_footer.php"); 
}
?>
